﻿@model List<HGShare.VWModel.TreeVModel>
@using HGShare.Site
@using Newtonsoft.Json
@{
    ViewBag.Title = "分配模块";
    Layout = "~/Views/Shared/_HContentLayout.cshtml";
}
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>分配模块</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form>
                            <div class="form-group">
                                <div id="using_json">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <button class="btn btn-primary btn-sm" type="button" id="submitbtn">确定分配</button>
                                <button class="btn btn-white" type="button" onclick="window.history.back(-1);">取消</button>
                            </div>
                        </form>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
</div>
@section script_header
{
<!--树-->
<link href="@Url.StaticFile("~/hplus/css/plugins/jsTree/style.min.css")" rel="stylesheet" />
}
@section script_footer
{
    <!--树-->
    <script type="text/javascript" src="@Url.StaticFile("~/hplus/js/plugins/jsTree/jstree.min.js")"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            var tree = $("#using_json").jstree({
                "core": {
                    "multiple": true,
                    "data": @Html.Raw(JsonConvert.SerializeObject(Model))
                },
                "checkbox": {
                    "keep_selected_style": false //是否显示节点的选中样
                },
                "plugins": ["checkbox"]
            }).on('click.jstree', function(event) {
                //点击事件
            }).on('changed.jstree', function(e, data) {
                //选中事件
            }).on('ready.jstree', function() {
                /*默认选中已选模块*/
                tree.jstree().select_node(@Html.Raw(ViewBag.SelectedIds));
                tree.jstree().open_node(@Html.Raw(ViewBag.SelectedIds));
                open_node
            });
            /*提交选中的模块*/
            $("#submitbtn").on("click", function() {
                var selectednodeids = tree.jstree().get_checked();
                var ids = [];
                for (var i = 0; i < selectednodeids.length; i++) {
                    ids.push(selectednodeids[i].replace("tree_node_",''));
                }
                //更新数据
                hgajax.post("@Url.Action("AllocationModul", "Roles")", {rid:@ViewBag.RId,ids:ids.join(',')}, function(result) {
                    window.location.reload();
                });
            });
        });

    </script>
}